<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>职员修改</title>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all">
		<style>
			.empAddBox{
				margin: 0 auto;
				margin-top: 80px;
				border: solid gainsboro 1px;
				width: 80%;
				padding: 20px;
				height: 60%;
				
			}
		</style>

	</head>
	<body>
		<div class="empAddBox">
			<form class="layui-form layui-form-pane" method="post" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">职员编号</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeCode" name="employeeCode" lay-verify="required" placeholder="请输入职员编号" autocomplete="off"
						 class="layui-input">
					</div>
					<label class="layui-form-label">职员姓名</label>
					<div class="layui-input-inline">
						<input type="text" id="employeeName" name="employeeName" placeholder="输入职员编号,点击即可" autocomplete="off" class="layui-input"
						 readonly>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">基本工资</label>
					<div class="layui-input-inline">
						<input type="text" id="basicWage" name="basicWage" lay-verify="required" placeholder="请输入基本工资" autocomplete="off"
						 class="layui-input">
					</div>
					<label class="layui-form-label">岗位工资</label>
					<div class="layui-input-inline">
						<input type="text" id="stationWage" name="stationWage" lay-verify="required" placeholder="请输入岗位工资" autocomplete="off"
						 class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">津贴</label>
						<div class="layui-input-inline">
							<input type="text" id="allowance" name="allowance" lay-verify="required" placeholder="请输入津贴" autocomplete="off"
							 class="layui-input">
						</div>
						<label class="layui-form-label">日期</label>
						<div class="layui-input-inline">
							<input type="text" lay-verify="required" name="payoffDate" id="date1" placeholder="请选择日期" autocomplete="off"
							 class="layui-input">
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">确认添加</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</form>
		</div>
		<!-- <script type='text/javascript' src="js/jquery-3.4.1.min.js"></script> -->
		<script src="../layui/layui.js" charset="utf-8"></script>

		<script>
			// function inputEmployeeName() {
			// 	document.getElementById("employeeCode").value
			// 	// var employeeCode = $("#employeeCode").val();
			// 	var employeeCode = document.getElementById("employeeCode").value;
			// 	alert(employeeCode);
			// }





			layui.use(['form', 'laydate', 'jquery'], function() {

				var form = layui.form,
					layer = layui.layer,
					// layedit = layui.layedit,
					laydate = layui.laydate;
				var $ = layui.$;


				//日期
				laydate.render({
					elem: '#date1'
				});

				//创建一个编辑器
				// var editIndex = layedit.build('LAY_demo_editor');

				//自定义验证规则
				form.verify({
					title: function(value) {
						if (value.length < 5) {
							return '标题至少得5个字符啊';
						}
					},
					content: function(value) {
						layedit.sync(editIndex);
					}
				});


				//监听提交
				form.on('submit(demo1)', function(data) {
					var index = parent.layer.getFrameIndex(window.name);
					$.ajax({
						url: 'http://localhost:9000/application/wageAdd',
						type: 'post',
						dataType: 'json',
						data: {
							"employeeCode": data.field.employeeCode,
							"employeeName": data.field.employeeName,
							"basicWage": data.field.basicWage,
							"stationWage": data.field.stationWage,
							"allowance": data.field.allowance,
							"payoffDate": data.field.payoffDate,
						},
						success: function(data1) {
							// 异常处理
							if (data1.code == 0) {
								layer.msg(JSON.stringify(data1.message), {

								});

								setTimeout(function() {
									parent.layer.close(index);
									parent.window.location.reload();
								}, 3000);
							} else {
								layer.msg(JSON.stringify(data1.message), {

								});

								setTimeout(function() {
									window.location.href = "empwarning.html";
								}, 3000);

							}



						}
					})
					return false;
				});

				$('#employeeName').click(function() {
					var employeeCode = $("#employeeCode").val();
					if (employeeCode == null || employeeCode == "") {
						layer.msg("员工编号不能为空！", {

						});
					} else {
						$.ajax({
							url: 'http://localhost:9000/application/wageNameByCode',
							type: 'post',
							dataType: 'json',
							data: {
								"employeeCode": employeeCode
							},
							success: function(data1) {

								if (data1.code == 0) {
									if (data1.data != null && data1.data != '') {
										$("#employeeName").val(data1.data);
									} else {
										layer.msg("不存在此员工，请重新输入员工编号", {

										});
									}

								} else if (data1.code == -1) {
									layer.msg(data1.message, {

									});
								} else {
									layer.msg("发生意外，稍后重试", {

									});
								}

							}
						});
					}

				});


				//表单取值
				layui.$('#LAY-component-form-getval').on('click', function() {
					var data = form.val('example');

					alert(JSON.stringify(data));
				});

			});
		</script>

	</body>

</html>
